﻿#include"./minglib/spitringbuff.h"
#include"stdio.h"
#include <windows.h>

uint8_t ringBuff1ReadBuffer[50];
uint16_t ringBuff1PackLen;
SpitRingBuff_TypeDef ringBuff1 = { 0 };




uint8_t myUart2ReBuf0[55] = "a(1,_,78)\n";
uint8_t myUart2ReBuf1[55]="t(1,2)\n";
uint8_t myUart2ReBuf2[55] = "s(4444,7897,_)\n";

DWORD WINAPI fifoThreadWrite(LPVOID lpParameter)
{
   
    while (1) {
      
		for (int i = 0; i < strlen(myUart2ReBuf0); i++) {
			spitRingBuffWriteChar(&ringBuff1, myUart2ReBuf0[i]);
		}

		for (int i = 0; i < strlen(myUart2ReBuf1); i++) {
			spitRingBuffWriteChar(&ringBuff1, myUart2ReBuf1[i]);
			//Sleep(10);
		}
		
		for (int i = 0; i < strlen(myUart2ReBuf2); i++) {
			spitRingBuffWriteChar(&ringBuff1, myUart2ReBuf2[i]);
			Sleep(1);
		}

		for (int i = 0; i < strlen(myUart2ReBuf1); i++) {
			spitRingBuffWriteChar(&ringBuff1, myUart2ReBuf1[i]);
			Sleep(10);
		}

		Sleep(500);
    }
    return 0;
}


DWORD WINAPI fifoThreadRead(LPVOID lpParameter)
{
    while (1) {
		if (0 == spitRingBuffRead(&ringBuff1, ringBuff1ReadBuffer, &ringBuff1PackLen))
		{
			//读到的数据@数据长度@队列中数据包个数
			printf("\nR:%s@%d@%d", ringBuff1ReadBuffer, ringBuff1PackLen, ringBuff1.count);
		}

		Sleep(200);
    }
    return 0;
}


int main()
{
	//按换行符分割
	ringBuff1.enableReadLine = 1;

	 CreateThread(NULL, 0, fifoThreadWrite, NULL, 0, NULL);
	 CreateThread(NULL, 0, fifoThreadRead, NULL, 0, NULL);
	 while(1) {
		 Sleep(5000);
	 }
	return 0;
}